#include "hillpage.h"
#include "program.h"
#include "mainpage.h"

using namespace cocos2d;

CCScene* HillPageLayer01::scene()
{
	CCScene *scene = CCScene::node();
	HillPageLayer01 *layer = HillPageLayer01::node();
	scene->addChild(layer);
	return scene;
}
//-------------------------------------------------------------------
bool HillPageLayer01::init()
{
	if(!CCLayer::init() )
	{
		return false;
	}
	setIsKeypadEnabled(true);

	CCSize size = CCDirector::sharedDirector()->getWinSize();
	CCSprite* pSprite = CCSprite::spriteWithFile("bg_setting.jpg");
	pSprite->setPosition(ccp(size.width/2,size.height/2));
	this->addChild(pSprite,0);


	CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("setbtn.plist");
	CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("hillprog.plist");

	CCSprite* sprite_title = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("title_hill.png")); 


	//Hill 1
	CCSprite* sprite_hillA01 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("hillA_01.png"));
	CCSprite* sprite_hillA02 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("hillA_02.png"));
	sprite_hillA02->setPosition(ccp(3,-3));

	//Hill 2
	CCSprite* sprite_hillB01 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("hillB_01.png"));
	CCSprite* sprite_hillB02 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("hillB_02.png"));
	sprite_hillB02->setPosition(ccp(3,-3));

	//Hill 3
	CCSprite* sprite_hillC01 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("hillC_01.png"));
	CCSprite* sprite_hillC02 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("hillC_02.png"));
	sprite_hillC02->setPosition(ccp(3,-3));


	CCSprite* sprite_home01 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_home.png"));
	CCSprite* sprite_home02 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_home.png"));
	sprite_home02->setPosition(ccp(3,-3));

	CCSprite* sprite_back01 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_back.png"));
	CCSprite* sprite_back02 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_back.png"));
	sprite_back02->setPosition(ccp(3,-3));

	CCSprite* sprite_help01 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("help01.png"));
	CCSprite* sprite_help02 = CCSprite::spriteWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("help02.png"));


	float sbw = size.width / 1024;
	float sbh = size.height / 768;


	sprite_title->setPosition(ccp((sbw*512.0f), size.height - (sbh *135.0f)));
	this->addChild(sprite_title,0);


	CCMenuItemSprite* item_hillA = CCMenuItemSprite::itemFromNormalSprite(sprite_hillA01,sprite_hillA02,this,menu_selector(HillPageLayer01::menuHillACallback));
	item_hillA->setPosition(ccp((sbw*515.0f), size.height - (sbh *290.0f)));

	CCMenuItemSprite* item_hillB = CCMenuItemSprite::itemFromNormalSprite(sprite_hillB01,sprite_hillB02,this,menu_selector(HillPageLayer01::menuHillBCallback));
	item_hillB->setPosition(ccp((sbw*515.0f), size.height - (sbh *440.0f)));

	CCMenuItemSprite* item_hillC = CCMenuItemSprite::itemFromNormalSprite(sprite_hillC01,sprite_hillC02,this,menu_selector(HillPageLayer01::menuHillCCallback));
	item_hillC->setPosition(ccp((sbw*515.0f), size.height - (sbh *590.0f)));



	CCMenuItemSprite* item_home = CCMenuItemSprite::itemFromNormalSprite(sprite_home01,sprite_home02,this,menu_selector(HillPageLayer01::menuHomeCallback));
	item_home->setPosition(ccp((sbw*960.0f), size.height - (sbh *700.0f)));

	CCMenuItemSprite* item_back = CCMenuItemSprite::itemFromNormalSprite(sprite_back01,sprite_back02,this,menu_selector(HillPageLayer01::menuBackCallback));
	item_back->setPosition(ccp((sbw*860.0f), size.height - (sbh *700.0f)));

	CCMenuItemSprite* item_help = CCMenuItemSprite::itemFromNormalSprite(sprite_help01,sprite_help02,this,menu_selector(HillPageLayer01::menuHelpCallback));
	item_help->setPosition(ccp((sbw*980.0f), size.height - (sbh *70.0f)));

	CCMenu* pmenu = CCMenu::menuWithItems(item_back,item_home,item_help,item_hillA,item_hillB,item_hillC, NULL);
	pmenu->setPosition(CCPointZero);

	addChild(pmenu);


	return true;
}






//-------------------------------------------------------------------
void HillPageLayer01::menuHillACallback(cocos2d::CCObject *pSender)
{
	CCLog("Hill 1");
}
//-------------------------------------------------------------------
void HillPageLayer01::menuHillBCallback(cocos2d::CCObject *pSender)
{
	CCLog("Hill 2");
}
//-------------------------------------------------------------------
void HillPageLayer01::menuHillCCallback(cocos2d::CCObject *pSender)
{
	CCLog("Hill 2");
}

//-------------------------------------------------------------------
void HillPageLayer01::menuHelpCallback(cocos2d::CCObject *pSender)
{

}
//-------------------------------------------------------------------
void HillPageLayer01::menuHomeCallback(cocos2d::CCObject *pSender)
{
	CCScene* s = MainPageLayer01::scene();
	CCScene* pScene = CCTransitionCrossFade::transitionWithDuration(0.5f, s);
	CCDirector::sharedDirector()->replaceScene(pScene);
}
//-------------------------------------------------------------------
void HillPageLayer01::menuBackCallback(cocos2d::CCObject *pSender)
{
	CCScene* s = ProgramLayer01::scene();
	CCScene* pScene = CCTransitionCrossFade::transitionWithDuration(0.5f, s);
    CCDirector::sharedDirector()->replaceScene(pScene);
}